/*
Blender Game Engine Launcher
Copyright (C) 2011  Michael Goerlich and Matthias Esau

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SETTINGS_H
#define SETTINGS_H

#include <QFile>
#include <QString>
#include <QStringList>
#include <QDomNodeList>
#include <QDomDocument>
#include <QTextStream>

class Settings
{
private:
    /** Was the doc parsed correctly? */
    bool good;

    /** Document */
    QDomDocument doc;

    /** Links to the values of the document */
    QStringList resolutions;
    QDomNode customResolution;
    QString iconPath;
    QString logoPath;
    QString playerPath;
    QString blendfilePath;
    QString windowTitle;
    QDomNode selectedResolution;
    QDomNode selectedAntialiasing;
    QDomNode selectedFullscreen;

    /** We are not supposed to be constructed like that */
    Settings();

    /** Checks if the node has proposed name and saves the textNode in textVal */
    bool getTextNode(QDomNode& node, QString proposedName, QDomNode &textVal);

    /** Subfunctions to find nodes */
    bool readResolutions(QDomNode& resolutions);
    bool readPaths(QDomNode& paths);
    bool readUISettings(QDomNode& uisettings);
    bool readSelected(QDomNode& selected);
public:
    Settings(QString filename);

    inline bool isGood() { return good; }

    inline QStringList getResolutions() { return resolutions; }
    inline QString getIconPath() { return iconPath; }
    inline QString getLogoPath() { return logoPath; }
    inline QString getPlayerPath() { return playerPath; }
    inline QString getBlendfilePath() { return blendfilePath; }
    inline QString getWindowTitle() { return windowTitle; }

    inline QString getCustomResolution() { return customResolution.nodeValue(); }

    inline int getSelectedResolution() { return selectedResolution.nodeValue().toInt(); }
    inline int getSelectedAntialiasing() { return selectedAntialiasing.nodeValue().toInt(); }
    inline bool getSelectedFullscreen() { return selectedFullscreen.nodeValue()=="true"; }

    inline void setCustomResolution(QString val) { customResolution.setNodeValue(val); }
    inline void setSelectedResolution(int val) { selectedResolution.setNodeValue(QString::number(val)); }
    inline void setSelectedAntialiasing(int val) { selectedAntialiasing.setNodeValue(QString::number(val)); }
    inline void setSelectedFullscreen(bool val) { selectedFullscreen.setNodeValue(val ? "true":"false"); }

    bool writeTo(QString path);

    /** Regular expression to check resolutions */
    const static QRegExp resolution;
};

#endif // SETTINGS_H
